import mockAdapter from 'axios-mock-adapter'
import axios from 'axios'

import {
	mockSubjects,
	mockNews,
	mockTypeNews
} from './data.js'

//创建默认实例对象
let MockAdapter = new mockAdapter(axios)

export default{
    init(){
        MockAdapter.onGet('/subjects').reply(200,{
            code: 1001,
			msg: '请求成功',
			detail: mockSubjects()
        })

        MockAdapter.onGet('/news').reply(200, {
			code: 1001,
			msg: '请求成功',
			detail: mockNews()
		})

		MockAdapter.onGet('/news/type').reply(config => {
			const type = config.params
			// console.log(config)
			return new Promise((resolve, reject) => {
				resolve([
					200,
					{
						code: 1001,
						msg: '请求成功',
						detail: mockTypeNews(type) //返回数据
					}
				])
			})
		})
    }
}